home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / ctutor2.zip / GOTOEX.C < prev    next >
C/C++ Source or Header  |  1987-07-04  |  1KB  |  40 lines

  1.                                          /* Chapter 3 - Program 7 */
  2. main()
  3. {
  4. int dog,cat,pig;
  5.  
  6.    goto real_start;
  7.  
  8.    some_where:
  9.    printf("This is another line of the mess.\n");
  10.    goto stop_it;
  11.  
  12. /* the following section is the only section with a useable goto */
  13.    real_start:
  14.    for(dog = 1;dog < 6;dog = dog + 1) {
  15.       for(cat = 1;cat < 6;cat = cat + 1) {
  16.          for(pig = 1;pig < 4;pig = pig + 1) {
  17.             printf("Dog = %d  Cat = %d  Pig = %d\n",dog,cat,pig);
  18.             if ((dog + cat + pig) > 8 ) goto enough;
  19.          };
  20.       };
  21.    };
  22.    enough: printf("Those are enough animals for now.\n");
  23. /* this is the end of the section with a useable goto statement */
  24.  
  25.    printf("\nThis is the first line out of the spaghetti code.\n");
  26.    goto there;
  27.  
  28.    where:
  29.    printf("This is the third line of spaghetti.\n");
  30.    goto some_where;
  31.  
  32.    there:
  33.    printf("This is the second line of the spaghetti code.\n");
  34.    goto where;
  35.  
  36.    stop_it:
  37.    printf("This is the last line of this mess.\n");
  38.  
  39. }
  40.